package com.xuecheng.media.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xuecheng.media.mapper.MediaProcessHistoryMapper;
import com.xuecheng.content.model.po.MediaProcessHistory;
import com.xuecheng.media.service.MediaProcessHistoryService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Mia
 */
@Slf4j
@Service
public class MediaProcessHistoryServiceImpl extends ServiceImpl<MediaProcessHistoryMapper, MediaProcessHistory> implements MediaProcessHistoryService {

    @Autowired
    private MediaProcessHistoryMapper mediaProcessHistoryMapper;

    /**
     * 批量插入媒体处理记录
     *
     * @param list 媒体处理记录列表
     * @return 成功插入的记录数
     */
    @Override
    public int insertBatch(@Param("list") List<MediaProcessHistory> list){
        return mediaProcessHistoryMapper.insertBatch(list);
    }

    /**
     * 批量插入或更新媒体处理记录
     *
     * @param list 媒体处理记录列表
     * @return 成功操作的记录数
     */
    @Override
    public int batchInsertOrUpdate(@Param("list") List<MediaProcessHistory> list){
        return mediaProcessHistoryMapper.batchInsertOrUpdate(list);
    }

    @Override
    public int insert(MediaProcessHistory mediaProcessHistoryInsert) {
        return mediaProcessHistoryMapper.insert(mediaProcessHistoryInsert);
    }

    @Override
    public MediaProcessHistory selectByFileId(String fileId) {
        return mediaProcessHistoryMapper.selectOne(new LambdaQueryWrapper<MediaProcessHistory>().eq(MediaProcessHistory::getFileId,fileId));
    }
//    查询失败的记录
    @Override
    public List<MediaProcessHistory> selectFailFileID() {
        return mediaProcessHistoryMapper.selectList(new LambdaQueryWrapper<MediaProcessHistory>().eq(MediaProcessHistory::getStatus, "3")
                .lt(MediaProcessHistory::getFailCount, "3"));
    }
}
